<?php 
	
	function thumb($spath,$urlname){

	 $imgpath=$spath.$urlname;

	
	 $old=getimagesize($imgpath);
 
	 $thumb_w=$old[0]/2;
	 $thumb_h=$old[1]/2;

	 switch ($old[2]) {
	 	case '1':
	 		$old_img=imagecreatefromgif($imgpath);
	 		break;
	 	case '2':

	 		$old_img=imagecreatefromjpeg($imgpath);
	 		break;
	 	default:
	 		$old_img=imagecreatefrompng($imgpath);
	 		break;
	 };

	 $thumb=imagecreatetruecolor($thumb_w,$thumb_h);

	  imagecopyresized( $thumb ,$old_img,0 ,0 ,0, 0,$thumb_w,$thumb_h,$old[0],$old[1]);

	  ob_clean();

	  $thumbpath=$spath.'thumb_'.$urlname;

	  switch ($old[2]) {
	  	case '1':
	  		imagegif($thumb,$thumbpath);
	  		break;
	  	case '2':
	  		imagejpeg($thumb,$thumbpath);
	  		break;	
	  	default:
	  		imagepng($thumb,$thumbpath);
	  		break;
	  };


	  imagedestroy($thumb);


	  return $thumbpath;

}
?>
